package com.zhongchaowuye.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.Page;
import com.zhongchaowuye.pojo.A_ZhL_PZh;
import com.zhongchaowuye.service.A_ZhL_PZhService;

@Controller
@RequestMapping("/a_ZhL_PZh")
public class A_ZhL_PZhController {

	@Resource
	private A_ZhL_PZhService a_ZhL_PZhService;
	
	@RequestMapping(value ="/getA_ZhL_PZh",method = RequestMethod.POST)
	@ResponseBody
	//根据id获取A_ZhL_PZh对象信息
	public Map<String,Object> getA_ZhL_PZh(HttpServletRequest request,A_ZhL_PZh pzh){
		Map<String,Object> m=new HashMap<>();
		Map<String,Object> reMap=new HashMap<>();
		try {
			A_ZhL_PZh a_ZhL_PZh=a_ZhL_PZhService.getA_ZhL_PZh(pzh);
			reMap.put("a_ZhL_PZh", a_ZhL_PZh);
			reMap.put("status", "success");
			reMap.put("message", "OK");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
			reMap.put("message", "ERROR："+e.getMessage());
		}
		return reMap;
	}

	@RequestMapping(value ="/getA_ZhL_PZhList",method = RequestMethod.POST)
	@ResponseBody
	//获取列表
	public Map<String,Object> getA_ZhL_PZhList(HttpServletRequest request,A_ZhL_PZh a_ZhL_PZh){
		Map<String,Object> reMap=new HashMap<>();//定义返回值，其中有一项必须是集合，先按照下面的写法
		try {
			//List<Map<String,Object>> rList=a_ZhL_PZhService.getA_ZhL_PZhList(a_ZhL_PZh); //不带分页（注意实现类中的相应写法）
			Page<Map<String,Object>> rList = (Page)a_ZhL_PZhService.getA_ZhL_PZhList(a_ZhL_PZh);
			
			//System.out.println(rList);
			reMap.put("rows", rList);
			reMap.put("total", rList.getTotal());
			reMap.put("pageIndex", a_ZhL_PZh.getPageIndex());
			reMap.put("pageSize", a_ZhL_PZh.getPageSize());
			reMap.put("status", "success");
			reMap.put("message", "OK");
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
			reMap.put("message", "ERROR");
		}
		return reMap;
	}
	
	@RequestMapping(value ="/insertA_ZhL_PZh",method = RequestMethod.POST)
	@ResponseBody
	//添加
	public Map<String,Object> insertA_ZhL_PZh(HttpServletRequest request,A_ZhL_PZh a_ZhL_PZh)   
	{
		Map<String,Object> reMap=new HashMap<>();//返回值map
		try 
		{
			int flag=a_ZhL_PZhService.insertA_ZhL_PZh(a_ZhL_PZh);
			//int flag = 0;
			if(flag>0)
			{
				reMap.put("status", "success");
				reMap.put("message", "OK");
			}
			else
			{
				reMap.put("status", "error");
				reMap.put("message", "ERROR");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
		}
		return reMap;
	}
	
	@RequestMapping(value ="/updateA_ZhL_PZh",method = RequestMethod.POST)
	@ResponseBody
	//修改
	public Map<String,Object> updateA_ZhL_PZh(HttpServletRequest request,A_ZhL_PZh a_ZhL_PZh)   
	{
		Map<String,Object> reMap=new HashMap<>();//返回值map
		try 
		{
			int flag=a_ZhL_PZhService.updateA_ZhL_PZh(a_ZhL_PZh);
			if(flag>0)
			{
				reMap.put("status", "success");
				reMap.put("message", "OK");
			}
			else
			{
				reMap.put("status", "error");
				reMap.put("message", "ERROR");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
		}
		return reMap;
	}
	
	@RequestMapping(value ="/delA_ZhL_PZh",method = RequestMethod.POST)
	@ResponseBody
	//软删除
	public Map<String,Object> delA_ZhL_PZh(HttpServletRequest request,A_ZhL_PZh a_ZhL_PZh)   
	{
		Map<String,Object> reMap=new HashMap<>();//返回值map
		Map<String,Object> m=new HashMap<>();
		try 
		{
			int flag=a_ZhL_PZhService.delA_ZhL_PZh(a_ZhL_PZh);
			if(flag>0)
			{
				reMap.put("status", "success");
				reMap.put("message", "OK");
			}
			else
			{
				reMap.put("status", "error");
				reMap.put("message", "ERROR");
			}
			
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			reMap.put("status", "error");
		}
		return reMap;
	}
}
